<!DOCTYPE html>
<html>
<head>
<title>GunDomain教程</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) */
/* Author: Nicolas Hery - http://nicolashery.com */
/* Version: b13fe65ca28d2e568c6ed5d7f06581183df8f2ff */
/* Source: https://github.com/nicolahery/markdownpad-github */

/* RESET
=============================================================================*/

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
}

/* BODY
=============================================================================*/

body {
  font-family: Helvetica, arial, freesans, clean, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  background-color: #fff;
  padding: 20px;
  max-width: 960px;
  margin: 0 auto;
}

body>*:first-child {
  margin-top: 0 !important;
}

body>*:last-child {
  margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
  margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
  margin: 20px 0 10px;
  padding: 0;
  font-weight: bold;
  -webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
  font-size: inherit;
}

h1 {
  font-size: 28px;
  color: #000;
}

h2 {
  font-size: 24px;
  border-bottom: 1px solid #ccc;
  color: #000;
}

h3 {
  font-size: 18px;
}

h4 {
  font-size: 16px;
}

h5 {
  font-size: 14px;
}

h6 {
  color: #777;
  font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
  margin-top: 0;
  padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
  margin-top: 0;
  padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
  margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
  color: #4183C4;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
  padding-left: 30px;
}

ul li > :first-child, 
ol li > :first-child, 
ul li ul:first-of-type, 
ol li ol:first-of-type, 
ul li ol:first-of-type, 
ol li ul:first-of-type {
  margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
  margin-bottom: 0;
}

dl {
  padding: 0;
}

dl dt {
  font-size: 14px;
  font-weight: bold;
  font-style: italic;
  padding: 0;
  margin: 15px 0 5px;
}

dl dt:first-child {
  padding: 0;
}

dl dt>:first-child {
  margin-top: 0px;
}

dl dt>:last-child {
  margin-bottom: 0px;
}

dl dd {
  margin: 0 0 15px;
  padding: 0 15px;
}

dl dd>:first-child {
  margin-top: 0px;
}

dl dd>:last-child {
  margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
  font-size: 12px;
  font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
  margin: 0 0px;
  padding: 0px 0px;
  white-space: nowrap;
  border: 1px solid #eaeaea;
  background-color: #f8f8f8;
  border-radius: 3px;
}

pre>code {
  margin: 0;
  padding: 0;
  white-space: pre;
  border: none;
  background: transparent;
}

pre {
  background-color: #f8f8f8;
  border: 1px solid #ccc;
  font-size: 13px;
  line-height: 19px;
  overflow: auto;
  padding: 6px 10px;
  border-radius: 3px;
}

pre code, pre tt {
  background-color: transparent;
  border: none;
}

kbd {
    -moz-border-bottom-colors: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background-color: #DDDDDD;
    background-image: linear-gradient(#F1F1F1, #DDDDDD);
    background-repeat: repeat-x;
    border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
    border-image: none;
    border-radius: 2px 2px 2px 2px;
    border-style: solid;
    border-width: 1px;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    line-height: 10px;
    padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
  border-left: 4px solid #DDD;
  padding: 0 15px;
  color: #777;
}

blockquote>:first-child {
  margin-top: 0px;
}

blockquote>:last-child {
  margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
  clear: both;
  margin: 15px 0;
  height: 0px;
  overflow: hidden;
  border: none;
  background: transparent;
  border-bottom: 4px solid #ddd;
  padding: 0;
}

/* TABLES
=============================================================================*/

table th {
  font-weight: bold;
}

table th, table td {
  border: 1px solid #ccc;
  padding: 6px 13px;
}

table tr {
  border-top: 1px solid #ccc;
  background-color: #fff;
}

table tr:nth-child(2n) {
  background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
  max-width: 100%
}
</style>
</head>
<body>
<h1>GunDomain教程</h1>
<hr />
<h2>前提，把mod加入到项目中</h2>
<p>eclipse用户，右键项目-Build Path-Add Libraries,然后把本mod加入到外部库即可；</p>
<p>idea用户，File-Project Structure-选择Modules（或者按Ctrl+Alt+Shift+S），然后添加即可；</p>
<p><img src="https://i.imgur.com/KRVhdOz.png" /></p>
<p><img src="https://i.imgur.com/2oKwXG5.png" /></p>
<h2>正题1.制作一个自己的枪械</h2>
<p>首先，你需要继承<code>team.unstudio.gundomain.common.api</code>包下的<code>ItemGunMain</code>类，这个类里面提供了枪械的各种属性及参数，这里我们直接继承即可。</p>
<pre><code>public class GunTest extends ItemGunMain {

    public GunTest(String name) {
        super(name);
        this.setCreativeTab(CreativeTabsLoader.CreativeTabs);//设置创造标签栏
    }

    public Entity getBullet(World w, EntityPlayer p) {
        return new EntityBullet();//这里返回子弹的实体，具体子弹的射击轨道等功能需要自己去写
    }

    public boolean isSnipe() {//这个方法设置该枪械是否为狙击类型的枪，如果是，右键会打开狙击界面，如果不是，右键直接瞄准
        return false;
    }
}
</code></pre>

<p>然后我们就可以在客户端代理中进行枪械的注册了<code>CommonProxy</code></p>
<p>我们先new一个枪械的对象</p>
<pre><code>public static GunTest gunTest = new GunTest(&quot;gunTest&quot;); 
</code></pre>

<p>这边你可以选择自己根据<code>team.unstudio.gundomain.common.api</code>下的<code>IGunData</code>类中的set方法，进行枪械各种属性的设置，也可以选择我这边提供的注册方法<code>team.unstudio.gundomain.common.item.gun.GunLoader#registerGun</code>方法进行注册，我这边拿Mod中士兵76的脉冲步枪来做例子：</p>
<pre><code>GunLoader.registerGun(sevenSix, &quot;sevenSix&quot;, 85, 25, 25, 2, 4, 66, 25, -1f, -0.55f, 2.0f, 2.5f, 0f, 0.1f, 20, 1.25f, 0.25f);
</code></pre>

<p>这些属性分别是</p>
<ol>
<li><code>ItemGunMain gun</code>	(你new出来的枪械对象)</li>
<li><code>String name</code>	(枪械的名称)</li>
<li><code>int cd</code>	(换弹时间，这边是以tick为单位的，MC中1秒=20tick)</li>
<li><code>int maxClip</code>	(枪械的最大子弹容量)</li>
<li><code>int fireDamage</code>	(枪械的伤害值)</li>
<li><code>int fireTime</code>	(枪械的射击间隔)</li>
<li><code>int width</code>	(枪械右下角2D贴图的长度)</li>
<li><code>int height</code>	(枪械右下角2D贴图的宽度)</li>
<li><code>float fireTextureX,fireTextureY,fireTextureZ</code>	(枪口火焰的坐标)</li>
<li><code>float pitch,recovery</code>	(设置枪械后坐力和后坐力回复值这里的后坐力：每一发子弹以后，进行一次玩家屏幕上移，连射的话这个值会递增（点击左键递增）这里的后坐力回复值：这里的回复值是每次停止设计或子弹打完时，屏幕会有一个小幅度下移（递增）)</li>
<li><code>float recoil</code>	(这里指的是模型渲染时，枪械渲染的抖动效果的后坐力)</li>
<li><code>int crossHairs</code>	(这里指的是鼠标准星的缩放，开枪时的准星扩散)</li>
<li><code>float aim</code>	(这里指的是玩家按右键进行瞄准时，模型进行的位移，防止过多或者过少位移)</li>
<li><code>float mouseSensitivity</code>	（这里是玩家开枪时候的鼠标速度，这个属性是为了让玩家有压枪的体验……，如果不需要的话，设置为0.5f即可）</li>
</ol>
<p>这样我们的第一个枪械就设置完成了！然后我来讲一下材质，模型，声音文件的设置。</p>
<h2>正题2.枪械模型的渲染</h2>
<p>枪械模型的渲染部分，我们这边继承<code>team.unstudio.gundomain.common.api.GunRender</code>类，然后构造函数如下：</p>
<pre><code>public GunTestRender() {
    super(0, 0, 0.0f);
}
</code></pre>

<p>然后根据开发者需要的部分，进行传递参数的设置。
然后我们开始写渲染部分：（我这边用Mod中的一个枪械渲染类进行举例）</p>
<pre><code>public static IModelCustom standModel = null;
public TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
public static ResourceLocation modelLocation = new ResourceLocation(&quot;modid&quot;, &quot;models/item/gunTest.obj&quot;);
public static ResourceLocation texture = new ResourceLocation(&quot;modid&quot;, &quot;models/item/gunTest.png&quot;);
public void renderItem(ItemRenderType type, ItemStack item, Object ... data) {

  if(standModel == null) {//判断模型是否为null，如果为null，加载模型
     standModel = AdvancedModelLoader.loadModel(modelLocation);
  }

  switch(type) {
  case EQUIPPED://第三人称的模型渲染
     GL11.glPushMatrix();
     renderEngine.bindTexture(texture);//绑定贴图
     GL11.glTranslatef(1.3F, 0.2F + rightClickTranslateY / 5.0F, 0.1F);
     GL11.glScalef(0.02F, 0.02F, 0.02F);
     GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
     GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
     GL11.glRotatef((float)reload, 0.0F, 0.0F, 1.0F);
     GL11.glRotatef((float)rightClickRotateP, 0.0F, 1.0F, 0.0F);
     GL11.glRotatef((float)rightClickRotateY, -1.0F, 0.0F, 0.0F);
     standModel.renderAll();//渲染模型
     GL11.glPopMatrix();
     return;
  case EQUIPPED_FIRST_PERSON://第一人称的模型渲染
     GL11.glPushMatrix();
     if(!GunRender.aim) {
        renderEngine.bindTexture(texture);//绑定贴图
        GL11.glTranslatef(4.0F - transol.floatValue() + rightClickTranslateP, -1.0F + rightClickTranslateY, 0.6F - aimNumber);
        GL11.glScalef(0.08F, 0.08F, 0.08F);
        GL11.glRotatef(90.0F, 0.0F, 0.0F, 1.0F);
        GL11.glRotatef(-60.0F, 0.0F, 0.0F, 1.0F);
        GL11.glRotatef(-1.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef((float)rotate, 0.0F, 0.0F, 100.0F);
        GL11.glRotatef((float)reload, 0.0F, 0.0F, 1.0F);
        GL11.glRotatef((float)rightClickRotateP, 0.0F, -1.0F, 0.0F);
        GL11.glRotatef((float)rightClickRotateY, 1.0F, 0.0F, 0.0F);
        standModel.renderAll();//渲染模型
     }
     GL11.glPopMatrix();
     return;
  default:
  }
}
</code></pre>

<p>这些平移旋转缩放部分所需要的参数开发者可以不用管，然后直接对自己模型的渲染调试即可。</p>
<p>上面的写完以后，我们在客户端代理<code>ClientProxy</code>类下，进行对物品的注册</p>
<pre><code>MinecraftForgeClient.registerItemRenderer(CommonProxy.gunTest, new GunTestRender());
</code></pre>

<p>然后我们根据上面设置上面设置的模型和贴图位置，添加你的模型和贴图即可，然后我们打开游戏就可以看到一个完整的枪械了！</p>
<h2>3.题外，子弹实体</h2>
<p>说实话，子弹实体这边的话，写过实体的开发者应该都能做，这个我就不多讲了，实体没有API，所以开发者大可发挥想象力，制作各种子弹，给子弹渲染各种效果都可以，对于不会制作实体的开发者，我这边白玉楼之梦的<a href="http://blog.hakugyokurou.net/?p=340" title="教程">实体教程</a>
(如果加载不出来，多刷新几次即可)</p>

</body>
</html>
<!-- This document was created with MarkdownPad, the Markdown editor for Windows (http://markdownpad.com) -->
